﻿using System;
using nRoute.Components;
using nRoute.Navigation.Mapping;
using nRoute.Samples.SiteMapClient.Views;
using nRoute.ViewModels;

namespace nRoute.Samples.SiteMapClient.ViewModels
{
	public class HomeViewModel : NavigationViewModelBase
	{
		private const string LASTVIEWED_KEY = "__LastViewedKey";
		private const string PAGE_TITLE = "Home";

		public HomeViewModel()
		{
			base.Title = PAGE_TITLE;
		}

		public DateTime? LastViewed { get; private set; }

#region State Management

		protected override void OnRestoreState(ParametersCollection state)
		{
			if (state != null && state.ContainsKey(LASTVIEWED_KEY))
			{
				this.LastViewed = Convert.ToDateTime(state[LASTVIEWED_KEY]);
				NotifyPropertyChanged(() => LastViewed);
			}
		}

		protected override ParametersCollection OnSaveState()
		{
			return new ParametersCollection() 
            {
                new Parameter(LASTVIEWED_KEY, DateTime.Now)
            };
		}

#endregion

	}
}